import java.util.*;

public class demo {
    public static void main(String[] args) {
        Information information = new Information();
        information.stroge();
        boolean flag = true;
        do{
            System.out.println("教务系统");
            System.out.println("请选择操作");
            System.out.printf("");
            System.out.println(" 1. 增加信息 "+" 2. 删除信息 "+" 3. 更改信息 ");
            System.out.println(" 4. 查询信息(学号) "+" 5. 查询信息(姓名) "+" 6. 查询信息(全部) ");
            System.out.println("0.退出系统");
            System.out.println("请输入:");
            Scanner scanner = new Scanner(System.in);
            int tmp = scanner.nextInt();
            switch (tmp){
                case 1://增加信息
                    information.addStudent();
                    break;
                case 2://删除信息
                    information.deleteone();
                    break;
                case 3://更改信息
                    break;
                case 4://查询信息(学号)
                    information.checkone();
                    break;
                case 5://查询信息(姓名)
                    information.checkName();
                    break;
                case 6://查询信息(全部)
                    information.checkall();
                    break;
                case 0:
                    System.out.println("退出系统");
                    flag = false;
                    break;
                default:
                    System.out.println("输入有误，重新输入!!!");
            }
        }while(flag);
        //初始化表格信息
    }
}

class Information {
    TreeMap<Integer, Studentinfo> map = new TreeMap<>();

    //建设Treemap.
    public TreeMap<Integer, Studentinfo> stroge() {
        map.put(1, new Studentinfo("小白", "803", "123456789"));
        map.put(123, new Studentinfo("小白3", "804", "123456789"));
        map.put(1234, new Studentinfo("小白2", "805", "12345678559"));
        map.put(15555, new Studentinfo("小黑", "806", "12345675589"));
        map.put(12, new Studentinfo("小白", "807", "123422256789"));
        return map;
    }

    //查询全部 遍历
    public void checkall() {
        for (Map.Entry<Integer, Studentinfo> tmplist : map.entrySet()) {
            int id = tmplist.getKey();
            Studentinfo info = tmplist.getValue();
            System.out.println("学号" + id + "姓名" + info.getName() + "班级" + info.getClassroom() + "电话" + info.getPhonenumber());
        }
    }

    //查询单个
    public void checkone() {
        System.out.println("请输入你想查询的id");
        Scanner scanner = new Scanner(System.in);
        int key = scanner.nextInt();
        Studentinfo value = map.get(key);
        if (map.get(key) == null) {
            System.out.println("你查询的学号不存在");
        } else {
            System.out.println("你查询的信息为:" + "学号" + key + " 姓名" + value.getName() + " 班级" + value.getClassroom() + " 电话" + value.getPhonenumber());
        }
    }

    //删除一个人
    public void deleteone() {
        System.out.println("请输入你想删除的id");
        Scanner scanner = new Scanner(System.in);
        int key = scanner.nextInt();
        if (map.remove(key) == null) {
            System.out.println("你想删除的信息不存在");
        } else {
            System.out.println("已删除");
        }
        map.remove(key);
    }
    //查找名字
    public void checkName() {
        System.out.println("请输入你想要查询的名字");
        Scanner scanner = new Scanner(System.in);
        String nameToFind = scanner.next();
        boolean found = false; // 标识是否找到了对应信息
        for (Map.Entry<Integer, Studentinfo> entry : map.entrySet()) {
            int id = entry.getKey();
            Studentinfo info = entry.getValue();
            if (info.getName().equals(nameToFind)) {
                System.out.println("学号：" + id + "，姓名：" + info.getName() + "，班级：" + info.getClassroom() + "，电话：" + info.getPhonenumber());
                found = true; // 标记找到了对应信息
            }
        }
        if (!found) { // 如果循环结束后未找到信息，则输出提示信息
            System.out.println("未找到姓名为 " + nameToFind + " 的学生信息。");
        }
    }
    //增加信息
    public void addStudent() {
        System.out.println("请输入学号");
        int id = new Scanner(System.in).nextInt();
        System.out.println("请输入名字");
        String name = new Scanner(System.in).next();
        System.out.println("请输入班级");
        String classNumber = new Scanner(System.in).next();
        System.out.println("请输入手机");
        String phoneNumber = new Scanner(System.in).next();
        map.put(id, new Studentinfo(name, classNumber, phoneNumber));
    }

}
class Studentinfo{
    private String name;
    private String classroom;
    private String phonenumber;

    public Studentinfo(String name, String classroom, String phonenumber) {
        this.name = name;
        this.classroom = classroom;
        this.phonenumber = phonenumber;
    }

    public String getName() {
        return name;
    }

    public String getClassroom() {
        return classroom;
    }

    public String getPhonenumber() {
        return phonenumber;
    }
}